#include <iostream>
using namespace std;
int g[1000];


int main()
{
	long long a,b;
	int m;
	while(cin>>m){
		if(m==0) break;
		cin>>a>>b;
		long long temp;
		temp=a+b;
		if(temp==0) {
			cout<<0<<endl;
			continue;
		}
		int count_g=0;
		while(temp>0){
			g[count_g]=temp%m;
			temp=temp/m;
			count_g+=1;
		}
		for(int i=count_g-1;i>=0;i--){
			if(i==0) cout<<g[i]<<endl;
			else cout<<g[i];
		}
	}
}
